#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;
void handler(int signo)
{
    if (waitpid(-1, NULL, WNOHANG) < 0)
        cout << "waitpid() error" << endl;
    else
    {
        cout << "the child process is finished" << endl;
        sleep(10);
    }
}
int main()
{
    signal(SIGCHLD, handler);
    pid_t child_pid = fork();
    if (child_pid > 0)
    {
        sleep(30);
        cout << "the parent process is finished" << endl;
    }
    else
        exit(0);
}